{% extends "topic/visualization/result_basic.html" %}


{% block mainbody %}
    <script src="/static/js/echarts.min.js"></script>

    <div id="main" style="width: 600px;height:400px;"></div>

    <script type="text/javascript">
        window.addEventListener("message", function (evt) {
            function timeline_format_data(t) {
                var res = {
                    'name': [],
                    'time': [],
                    'series': []
                };
                for (var name in t) {
                    res['name'].push(name);
                    res['series'].push({
                        name: name,
                        type: 'line',
                        data: t[name]
                    });
                    var _len = t[name].length;
                }
                for (var i = 0; i < _len; i++) {
                    res['time'].push(i);
                }
                return res;
            }

            var data = JSON.parse(evt.data);
            var res = timeline_format_data(data);
            draw(res);
        }, false);


        function draw(data) {
            var main = $("#main"), body = $("body");
            main.width(body.width());
            main.height(body.width() / 1.34);

            var myChart = echarts.init(document.getElementById('main'));
            // 指定图表的配置项和数据
            option = {
                title: {
                    text: 'Hashtags时间变化图'
                },
                tooltip: {
                    trigger: 'axis'
                },
                dataZoom: [
                    {
                        show: true,
                        realtime: true,
                        start: 0,
                        end: 100
                    },
                    {
                        type: 'inside',
                        realtime: true,
                        start: 0,
                        end: 100
                    }
                ],
                legend: {
                    data: data['name']
                },
                grid: {
                    left: '3%',
                    right: '4%',
                    bottom: '10%',
                    containLabel: true
                },
                toolbox: {
                    feature: {
                        saveAsImage: {}
                    }
                },
                xAxis: {
                    type: 'category',
                    boundaryGap: false,
                    data: data['time']
                },
                yAxis: {
                    type: 'value'
                },
                series: data['series']
            };
            myChart.setOption(option);
        }
    </script>


{% endblock %}